#include <stack>

using namespace std;

class MinStack {
private:
    stack<int> stack, min_stack;
public:
    MinStack() {}

    void push(int x) {
        stack.push(x);
        if (min_stack.empty() || x < min_stack.top()) {
            min_stack.push(x);
        } else {
            min_stack.push(min_stack.top());
        }
    }

    void pop() {
        stack.pop();
        min_stack.pop();
    }

    int top() {
        return stack.top();
    }

    int min() {
        return min_stack.top();
    }
};


